package sampleuiplugin;

import gamefw.framework.Coordinate;
import gamefw.uiplugin.IOutputManager;
import gamefw.uiplugin.IVisualResource;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class SampleVisualResource implements IVisualResource {
	
	private IOutputManager outputManager;
	
	private char[][] boardData;

	public SampleVisualResource(String visualResourceName, IOutputManager outputManager)
	throws Exception {
		this.outputManager = outputManager;
		
		BufferedReader reader = new BufferedReader(new FileReader(visualResourceName));
		
		ArrayList<String> lines = new ArrayList<String>();
		String line = null;
		int maxLen = 0;
		while ((line = reader.readLine()) != null) {
			if (line.length() > maxLen) {
				maxLen = line.length();
			}
			
			lines.add(line);
		}
		
		reader.close();
		
		this.boardData = new char[lines.size()][maxLen];
		for (int i = 0; i < lines.size(); ++i) {
			line = lines.get(i);
			line.getChars(0, line.length(), this.boardData[i], 0);
			
			for (int j = line.length(); j < maxLen; ++j) {
				this.boardData[i][j] = ' ';
			}
		}
	}

	@Override
	public void draw(Coordinate offset) {
		// TODO Auto-generated method stub
		this.outputManager.draw(offset, this);
	}
	
	public char[][] getBoardData() {
		return boardData;
	}

}
